<?php

use yii\helpers\Html;
use yii\helpers\ArrayHelper;
use yii\widgets\ActiveForm;

app\assets\AppAsset::register($this);
dmstr\web\AdminLteAsset::register($this);
$this->title = '';

/* @var $this yii\web\View */
/* @var $model app\models\News */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="news-form box box-primary">
    <?php 
        $form = ActiveForm::begin([
        'action' => ['update-check-status'],
        // 'method'=>'post',  //提交方法(*可省略默认POST*) 
        'id' => 'form-save', //设置ID属性 
          // 'options' => [ 
          //   'class' => 'form-horizontal', //设置class属性 
          // ], 
          // 'enableAjaxValidation' => true, 
          // 'validationUrl' => 'validate-view', 
    ]); ?>
    <div class="box-body table-responsive">
        <?=$form->field($model,'id')->hiddenInput()?>
        <?= $form->field($model, 'status')->dropDownList($data) ?>

        <?= $form->field($model, 'opt_note')->textarea(['rows' => 6]) ?>

    </div>
    <div class="box-footer">
        <?= Html::submitinput(Yii::t('app', '确认并保存'), ['class' => 'btn btn-success btn-flat form-submit']) ?>
    </div>
    <?php ActiveForm::end(); ?>
</div>



<?php //按需注入js, 放在</body>前面
$this->registerJs("
        $(function(){
            $('body').on('beforeSubmit', '#form-save', function (e) { 
                //提交之前禁用select disabled
                // $('[disabled]').each(function() {//移除disable,后台方可取值  
                //     if (parseInt($(this).val()) != -1) {  
                //         $(this).attr('disabled', false);  
                //     }  
                // }); 

                var form = $(this); 
                //返回错误的表单信息 
                if (form.find('.has-error').length) 
                { 
                  return false; 
                } 

                //表单提交 
                var trans_box_index = layer.msg('loading', {icon: 16, time: 0, shadeClose: true, shade: [0.7, '#000']});
                $.ajax({ 
                  url  : form.attr('action'), 
                  type  : 'post', 
                  dataType:'json',
                  data  : form.serialize(), 
                  success: function (response){
                    if(response.ok == 0){ 
                      window.parent.location.reload();
                    } else{
                        layer.alert(response.message, {title: '提示', btn: '', shadeClose: true, shade: [0.7, '#000'], offset: 'auto', time: 2000});
                    }
                  }, 
                  error : function (){ 
                    alert('系统错误'); 
                    return false; 
                  } 
                }); 
                return false; 
            }).on('submit', function(e){
                 e.preventDefault();
            });
        })

    ", \yii\web\View::POS_END);
 ?>

